package com.jinzihan.web;

import com.jinzihan.entity.Classroom;
import com.jinzihan.entity.Page;
import com.jinzihan.service.ClassroomService;
import com.jinzihan.service.impl.ClassroomServiceImpl;
import com.jinzihan.utils.WebUtils;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class ClientClassroomServlet extends BaseServlet {
    ClassroomService classroomService = new ClassroomServiceImpl();
    protected void page(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //1 获取请求的参数 pageNo 和 pageSize
        int pageNo = WebUtils.parseInt(req.getParameter("pageNo"), 1);
        int pageSize = WebUtils.parseInt(req.getParameter("pageSize"), Page.PAGE_SIZE);
        //2 调用 ClassroomService.page(pageNo，pageSize)：Page 对象
        Page<Classroom> page = classroomService.page(pageNo,pageSize);
        page.setUrl("client/clientClassroomServlet?action=page");
        //3 保存 Page 对象到 Request 域中
        req.setAttribute("page",page);
        //4 请求转发到 pages/manager/book_manager.jsp 页面
        req.getRequestDispatcher("/pages/client/index.jsp").forward(req,resp);
    }
}
